package com.base.Queue;

import com.base.helper.WebHelper;
import lombok.extern.log4j.Log4j;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 具体执行相关业务的业务类 （目前全部用来执行回调信息）
 */
@Log4j
public class DelayOrderWorker  implements Runnable {  
    private String URL; //回调的CallBack
    private Map<String,String> param; //回调的参数
    private Integer Time;  //回调的次数

    public DelayOrderWorker(String URL, Map<String, String> param, Integer time) {
        this.URL = URL;
        this.param = param;
        Time = time;
    }

    @Override
    public void run() {  
        // TODO Auto-generated method stub  
        //相关业务逻辑处理  目前只需要URL 别的参数的话暂时不管，以后再加
        String result=null;
        result = WebHelper.PostData(URL, null, "application/x-www-from-urlencoded", null);
        log.warn("首享话单回调返回结果:"+result);
        if (result==null && Time>0){
            Time--;
            DelayOrderWorker work = new DelayOrderWorker(URL,null,Time);
            DelayOrderQueueManager manager = DelayOrderQueueManager.getInstance();
            manager.put(work, 3000, TimeUnit.MILLISECONDS);
        }else if (result==null){
            log.error("发送回调信息失败:"+URL);
        }
    }
}